package org.sbbs.admin.manager.impl;

import jakarta.annotation.PostConstruct;
import org.sbbs.admin.dao.SysOrgRepo;
import org.sbbs.admin.entity.SysOrg;
import org.sbbs.admin.manager.SysOrgManager;
import org.sbbs.base.jpa.manager.impl.BaseTreeCacheManagerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 *
 * @author jenkins
 */
@Service
@Qualifier("sysOrgManager")
public class SysOrgManagerImpl extends BaseTreeCacheManagerImpl<SysOrg, Long, SysOrgRepo> implements SysOrgManager {

    @Autowired
    private SysOrgRepo repo;

    @PostConstruct
    public void init() {
        super.setRepo(repo);
        this.setCache(this.getCacheManager().getCache("sysOrgCache"));
        this.getCache().clear();
        this.load(true);
    }

//    @Override
//    public List<SysOrg> findChildren(SysOrg pid) {
//        List<SysOrg> sa = repo.findByPidOrderBySort(pid.getId());
//
//        for (SysOrg sysArea : sa) {
//            sysArea.setParent(pid);
//        }
//        return sa;
//    }
//
//    @Override
//    public Boolean hasChildren(SysOrg p) {
////        SysOrg p1 = new SysOrg();
////        p1.setId(p.getId());
////        
//        SysOrg e = new SysOrg();
//        e.setPid(p.getId());
//        Example<SysOrg> em = Example.of(e);
//        return repo.exists(em);
//    }
//
//    @Override
//    public void updateChildrenSort(List<SysOrg> children) {
//        for (int i = 0; i < children.size(); i++) {
//            SysOrg get = children.get(i);
//            get.setSort(i);
//        }
//        
//        this.repo.saveAllAndFlush(children);
//    }
}
